package com.le.tester.tip;

import com.le.tester.utils.Tools;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.time.DateUtils;

import java.sql.Array;
import java.sql.Timestamp;
import java.text.SimpleDateFormat;
import java.time.Instant;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.util.*;
import java.util.stream.Collectors;
import java.util.stream.Stream;

/**
 * createTime：2022/3/30 16:02
 * description：ArrayOutIndex
 */
public class ArrayOutIndex {
    public static void main(String[] args) throws Exception {


        List<String> tempListStr = new ArrayList<>();
        tempListStr.add("2022-07-13 08:00:00");
        tempListStr.add("2022-07-13 09:00:00");
        tempListStr.add("2022-07-13 10:00:00");

        String insert = "2022-07-13 09:30:00";
        tempListStr.add(insert);
        List<String> collect = tempListStr.stream().distinct().sorted().collect(Collectors.toList());
        System.out.println("tempListStr is " + collect);

        List<Integer> tempList = new ArrayList<>();
        for (int i = 0; i < 20; i++) {
            tempList.add(i, 0);
        }
        String result1 = StringUtils.join(tempList, ",");
        System.out.println(result1);
        String s = "1,2,3,4";
        String[] splitS = s.split(",");
        System.out.println(Arrays.toString(splitS));
        String temp = "wechat:pay:orderId:1436538732986634240";
        String[] split = temp.split(":");
        for (int i = 0; i < split.length; i++) {
            String orderId = split[split.length - 1];
            System.out.println("orderId is " + orderId);
        }


        Timestamp timestamp = Timestamp.valueOf(
                LocalDateTime.ofInstant(new Date(0).toInstant(), ZoneId.systemDefault()));
        System.out.println(timestamp);


        String tempTime = "20220519101547";
        String changeTimeStr = "20220519101547";
        Date time = DateUtils.parseDate(changeTimeStr, "yyyyMMddHHmmss");
        System.out.println(time);
        long changeTimeLong = Long.parseLong(changeTimeStr);
        //refundBookkeeping.setTimeEnd(DateUtil.parse(changeTime, "yyyy-MM-dd HHmmss").toTimestamp());
        LocalDateTime isLocalDateTime = Instant.ofEpochMilli(changeTimeLong).atZone(ZoneId.systemDefault()).toLocalDateTime();
        //refundBookkeeping.setTimeEnd(Timestamp.valueOf(isLocalDateTime));

//        String temp = "90,1,0";
//        //获取最大可预约的天数
//        Integer end = Integer.parseInt(temp.split(",")[0]);
//        //获取需要提前预约的天数
//        Integer begin = Integer.parseInt(temp.split(",")[1]);
//        System.out.println("end is " + end);
//
//
//        String s = "{\"default\":[{\"specs\":{\"specId\":21,\"specName\":\"bgColor\",\"isMultiple\":false,\"specWord\":\"背景颜色\",\"isNecessary\":true},\"specsvalues\":[\" 白色\",\"粉色\",\"紫色\",\"蓝色\",\"浅蓝色\"]}]}";
//
//        String result = s.replace(" ", "");
//        System.out.println("result is " + result);


//        String phone=" ";
//        boolean phone1 = Tools.isPhone(phone);
//
//        String callbackStr = "biz_content=%7B%22merId%22%3A%2230899917012000T%22%2C%22openId%22%3A%222088112350753733%22%2C%22orderId%22%3A%2220190226142842%22%2C%22cmbOrderId%22%3A%22100419022614284520605060%22%2C%22txnAmt%22%3A%221%22%2C%22currencyCode%22%3A%22156%22%2C%22payType%22%3A%22ZF%22%2C%22txnTime%22%3A%2220190226143025%22%2C%22endDate%22%3A%2220190226%22%2C%22endTime%22%3A%22143035%22%2C%22mchReserved%22%3A%22%E4%BF%9D%E7%95%99%E5%AD%97%E6%AE%B5%22%7D&sign=JtbJXHDo1nsyTGshBVuzDe8G0u0S96OjPdapSYFUKtKbZGW9ECjQGDtCynDhENBjLPjJqCfvgQSHojSt5MyqNq4acFC3OI7XsuILQsGvRdyvkOCEJx80%2BdqgZ%2ByIew8mXU1bQh2FLBECbrcFJYo9XN3X024yQ6TYINth7mpVV3eDaKo1oy4hdDKSDhfWVCQHtoeCAq%2FDZrn6c1MiQ7kKPimN1oAxXMgIZPJ2ePR1HtoZVsh%2BnNIPDhxM6mJX%2BQku5X4CaZiuMTggBZG1w8dlFABwRri9fzFnx4qWsxw9Xz8KgDuT9mk%2Fd4hZGveVKPWfiqCb1S3jqYHAzlHvtC5Wxg%3D%3D&encoding=UTF-8&version=0.0.1&signMethod=01";
//
//
//        Map<String, String> stringStringMap = new ArrayOutIndex().str2Map(callbackStr);
//        System.out.println(stringStringMap);
        List<Object> result = new ArrayList<>();
        System.out.println(result.size());
    }

    public Map<String, String> str2Map(String str) {
        //String t="{\"q1\":{\"value\":\"1\"},\"q2\":{\"value\":\"1\"},\"q3\":{\"value\":\"1\"},\"q4\":{\"value\":\"1\"},\"q5\":{\"value\":\"1\"},\"q6\":{\"value\":\"1\"},\"q7\":{\"value\":\"1\"},\"q8\":{\"value\":\"10\"},\"q9\":{\"value\":\"\"}}"
        Map<String, String> result = new HashMap<>();
        String[] results = str.split("&");
        if (results.length > 0) {
            for (String pair : results) {
                String[] kv = pair.split("=", 2);
                if (kv.length == 2) {
                    result.put(kv[0], kv[1]);
                }
            }
        }
        return result;
    }
}
